<?php
class Model_Products extends Model{
	public $table="  `nhtuna8s_ducngoco2`.products";
	
	public function insert_product($data){
		$this->insert($this->table,$data);
	}
	public function check_product($username,$id=""){
		if($id != ""){
			$where=array(
					"username" => "='$username'",
					"id"    => " != '$id'"
			);
		}else{
			$where="username='$username'";
		}
		$this->where($where);
		$this->getdata($this->table);
		if($this->num_rows() != 0){
			return FALSE;
		}else{
			return TRUE;
		}
	}
	public function listall(){
		$this->select("id,name,price");
		$this->order("id");
		$this->getdata($this->table);
		return $this->result_array();
	}
	public function delete_product($id){
		$this->where("id = '$id'");
		$this->delete($this->table);
	}
	public function get_product($id){
		$this->where("id = '$id'");
		$this->getdata($this->table);
		return $this->fetch();
	}
	public function update_product($data,$id){
		$this->where("id = '$id'");
		$this->update($this->table,$data);
	}
}